//
//  XMGTopCellSelectedView.m
//  weibo
//
//  Created by apple on 16/7/4.
//  Copyright © 2016年 DP. All rights reserved.
//

#import "XMGTopCellSelectedView.h"
//#import "XMGMessageTVc.m"
@interface XMGTopCellSelectedView ()
//@property (nonatomic, strong) XMGMessageTVc * messageVC;

@property (nonatomic, strong) NSMutableArray * Logs;
@end

@implementation XMGTopCellSelectedView

- (void)viewDidLoad {
    [super viewDidLoad];

#pragma mark - 自定义选中cell跳转界面的导航栏barButtonItem
    UIButton *btn =  [[UIButton alloc] init];
   
    [btn setImage:[UIImage imageNamed:@"navigationbar_back"] forState:UIControlStateNormal];
    
    [btn setImage:[UIImage imageNamed:@"navigationbar_back_highlighted"] forState:UIControlStateHighlighted];

    
    [btn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];

    [btn sizeToFit];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];

    
    UIButton *btnR = [[UIButton alloc]init];
    
    [btnR setTitle:@"设置" forState:UIControlStateNormal];
    
    [btnR setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    [btnR setTitleColor:[UIColor orangeColor] forState:UIControlStateHighlighted];
    
    [btnR sizeToFit];
    
    [btnR addTarget:self action:@selector(setting) forControlEvents:UIControlEventTouchUpInside];
    
  
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:btnR];
    
    
//    [SVProgressHUD showWithStatus:@"联网加载中"];
    
//    [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(hide) userInfo:nil repeats:YES];
    
    self.Logs = [[NSMutableArray alloc] init];
    
    NSDate *date = [[NSDate alloc] init];
    
    [self.Logs addObject:date];
 
    
    UIRefreshControl *rc = [[UIRefreshControl alloc] init];
    rc.attributedTitle = [[NSAttributedString alloc]initWithString:@"正在刷新"];

    [rc addTarget:self action:@selector(refreshTableView) forControlEvents:UIControlEventValueChanged];
    self.refreshControl = rc;
    
    
}
- (void)refreshTableView {
    
    if (self.refreshControl.refreshing) {
        
        self.refreshControl.attributedTitle = [[NSAttributedString alloc] initWithString: @"联网加载中..."];
  
        NSDate *date = [[NSDate alloc] init];
    
        [self performSelector:@selector(callBackMethod:) withObject:date afterDelay: 3];
    }
    
    
    
}

- (void)callBackMethod:(id)obj {
    
    [self.refreshControl endRefreshing];
    
    self.refreshControl.attributedTitle =[[NSAttributedString alloc]initWithString:@"刷新成功"];
    [self.Logs addObject:(NSDate *)obj];
    
//    NSLog(@"%@",obj);
    
    [self.tableView reloadData];
    
    
    
}



//- (void)hide {
//    
////    [SVProgressHUD dismiss];
//    
//}

- (void)back {
    
    
    
    [self.navigationController popViewControllerAnimated:YES];
    
}

#pragma mark - 跳转设置界面
- (void)setting {
    
    UITableView *view = [[UITableView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    
    view.backgroundColor = [UIColor purpleColor];
 
    [self.tableView addSubview:view];
    
   
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
    // Dispose of any resources that can be recreated.
}
- (void)dealloc{
    
    NSLog(@"%s",__func__);
}
#pragma mark - Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return [self.Logs count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *ID = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier: ID];
    }

    NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
    
    [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

    cell.textLabel.text = [dateFormat stringFromDate:[self.Logs objectAtIndex:[indexPath row ]]];
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
}




@end
